package com.sunday.framework.transaction.autoconfiguration;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @Description: 数据库查询 分页等设置
 * <p>
 * 默认实现 :
 * 1. MybatisPlus分页(数据查询分页支持)
 * 2. Mybatis自动扫描配置(@MapperScan)
 */
@ConditionalOnProperty(prefix = "sunday.framework.mybatis-plus", value = "mapperScan")
@MapperScan("${sunday.framework.mybatis-plus.mapperScan}")
public class DefaultMybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        /**
         * 分页
         */
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}